package com.mangowang.module.main.ui;

import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.mangowang.lib.common.base.BaseActivity;
import com.mangowang.lib.common.net.Apis;
import com.mangowang.lib.common.net.NetworkManager;
import com.mangowang.lib.common.net.interfaces.OnRequestCallBack;
import com.mangowang.lib.common.proto.Area;
import com.mangowang.lib.common.proto.MemberOuterClass;
import com.mangowang.lib.common.util.StatusBarUtil;
import com.mangowang.module.main.R;
import com.mangowang.module.main.R2;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class FeedBackActivity extends BaseActivity {
    @BindView(R2.id.content_et)
    EditText contentEt;
    @BindView(R2.id.submit_btn)
    Button submitBtn;
    @BindView(R2.id.back_iv)
    ImageView backIv;
    @BindView(R2.id.tv_title)
    TextView tvTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feed_back);
        ButterKnife.bind(this);
        StatusBarUtil.setStatusBarLightMode(this, Color.parseColor("#FFFFFF"), true);
        tvTitle.setText("意见反馈");
        backIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        submitBtn.setOnClickListener(v -> {
            submit();
        });
    }



    private void submit() {
        String s = contentEt.getText().toString();
        if (TextUtils.isEmpty(s)) {
            showToast("请输入反馈内容");
            return;
        }
        Area.area.Builder builder = Area.area.newBuilder();
        builder.setAreaName(s);
        showProgress();
        NetworkManager.INSTANCE.post(Apis.feedback_add, builder.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) {
                finish();
            }

            @Override
            public void onError(int code, String errorMessage) {
                showToast(errorMessage);
                hideProgress();
                if (code == 200) {
                    finish();
                }
            }
        });

    }
}
